/**
 * Created by Joseph on 2014/5/23.
 */
$(document).ready(function(){
    initClickable();
    initValidationAndIcheck();
});
//初始化点击事件
function initClickable(){
    //选择模块点击应用后提交到的地址
    var urlApply = $("#apply").data("url");
    $("#apply").click(function(){
        var checkedInput = new Array();
        var i=0;
        $("input[type='checkbox']").each(function(index){
            var flag = $(this).is(':checked');
            if(flag){
                checkedInput[i++] = Number($(this).attr("id"));
            }
        });
        $("#modules-input").val(JSON.stringify(checkedInput));
        $("#num").val("0");
         //alert("modules-input" + $("#modules-input").val()+"\nwhich tab：" + $("#num").val());
    });

    $('#edit-module').click(function(){

    });
}



function initValidationAndIcheck(){
    $('#add-form').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    "modules[name]": {
                        validators: {
                            notEmpty: {
                                message: '模块名称不能为空'
                            }
                        }
                    }
                }
            });
            $('#edit-form').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    "module[name]": {
                        validators: {
                            notEmpty: {
                                message: '模块名称不能为空'
                            }
                        }
                    },
                    "img": {
                        validators: {
                            notEmpty: {
                                message: '模块图片不能为空'
                            }
                        }
                    }
                }
                
            });

            //初始化icheck
            $('input').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square',
                increaseArea: '20%' // optional
            });
}
